package horarios;

import net.sourceforge.floggy.persistence.FloggyException;
import net.sourceforge.floggy.persistence.ObjectSet;
import net.sourceforge.floggy.persistence.Persistable;
import net.sourceforge.floggy.persistence.PersistableManager;

public class Dados implements Persistable {

	public void load(Filtro filtro) throws FloggyException {
		ObjectSet os = null;
		try {
			os = PersistableManager.getInstance().find(this.getClass(), filtro, null);
		} catch (FloggyException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		if (os.size() > 1) {
			throw new FloggyException("Existe mais de um registro com o mesmo nome!");

		} else {
			try {
				PersistableManager.getInstance().load(this, PersistableManager.getInstance().getId(os.get(0)));
			} catch (FloggyException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
	
	public void save() {
		try {
			PersistableManager.getInstance().save(this);
		} catch (FloggyException ex) {
			ex.printStackTrace();
		}
	}
	

}
